// src/router/index.jsx
import { createBrowserRouter, Navigate,Outlet } from 'react-router-dom';
import { lazy, Suspense } from 'react';




// 懒加载页面组件（优化首屏加载速度）
const Home = lazy(() => import('../pages/Home'));
const Login = lazy(() => import('../pages/Login'));
const List=lazy(() => import('../pages/List'));
const NotFound = lazy(() => import('../pages/404/index'));
const Upload =lazy(() => import('../pages/Upload'));
import { ProtectedRoute } from '../components/ProtectedRoute';

import InitApp from '@/pages/InitApp';

// 创建路由实例
const router = createBrowserRouter([
  {
    // 根路由（所有子路由共享 Navbar 和 Footer）
    path: '/',
    element:(<ProtectedRoute element={<InitApp />} />),
    children: [
      // 首页：默认路由（访问 / 时重定向到 /home）
      { index: true, element: <Navigate to="/home" replace /> },
      // 基础路由：首页
      { path: 'home', element: <Home /> },
      { path: 'list', element: <List /> },
      { path: 'upload', element: <Upload /> },
    ]
  },
  // 登录页（无需共享 Navbar/Footer，单独配置）
  { path: '/login', element: <Login /> },
  // 404 页面：匹配所有未定义的路由
  { path: '*', element: <NotFound /> }
]);

export default router;